  import {getSetting,chooseAddress,openSetting,showModal,showToast} from "../../utils/asyncWX.js"
  import regeneratorRuntime from '../../lib/runtime/runtime';
  Page({
  
    /**
     * 页面的初始数据
     */
    data: {
      address:{},
      cart:[],
      totalPrice:0,
      totalNum:0
    },
    
    onShow(){
      // 获取缓存中的收货地址信息
      const address=wx.getStorageSync("address");
      // 获取缓存中的购物车数据
      let cart=wx.getStorageSync("cart")||[];
      // 过滤后购物车数组
      cart=cart.filter(v=>v.checked);
      this.setData({
        address
      });
       // 总价格 总数量
       let totalPrice=0;
       let totalNum=0;
       cart.forEach(v=>{
           totalPrice+=v.num*v.goods_price;
           totalNum+=v.num;
       })
       this.setData({
         cart,
         totalPrice,
         totalNum,
         address
       });
      
    },
    // 点击支付
     handleOrderPay(){
     /* const token=wx.getStorageSync("token");
      if(!token){
        wx.navigateTo({
          url: '/pages/auth/index'
        });
          return;
      } */
      // 创建订单
      /* const header={Authorization:token};
      const order_price=this.data.totalPrice;
      const consignee_addr=this.data.address.all;
      const cart = this.data.cart;
      let goods=[];
      cart.forEach(v=>goods.push({
        goods_id:v.goods_id,
        goods_number:v.num,
        goods_price:v.goods_price
      }))
      // 发送请求 创建订单
      const res=await Request({url:'/my/order/create',method:"POST",data:orderParams,header});
      console.log(res);*/
      wx.showToast({
        title: '支付成功',
        icon: 'success',
        image: '',
        duration: 1500,
        mask: true
      });
      let newCart=wx.getStorageSync("cart");
      newCart=newCart.filter(v=>!v.checked);
      wx.setStorageSync("cart",newCart);
    } 
  })